#!/bin/bash

remote_server="root@116.62.79.131"
remote_directory="/usr/ops/lib/node1/"

# 循环遍历每个文件
for file in *.jar; do
  # 判断远程服务器上是否存在同名的文件
  ssh $remote_server "[ -f $remote_directory$file ]"
  if [ $? -eq 0 ]; then
    # 如果文件存在，则进行备份
    now=$(date +'%Y%m%d_%H%M')
    ssh $remote_server "cd $remote_directory && mv $file ../node-bak/${file%.jar}_$now.jar.bak"
  fi

  # 上传文件
  scp $file $remote_server:$remote_directory
done

read -n 1 -s -r -p $'\n'"Press any key to exit"